<?php

namespace common\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Sctotal;

/**
 * SctotalSearch represents the model behind the search form about `common\models\Sctotal`.
 */
class SctotalSearch extends Sctotal
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['t_id', 't_name', 'bei2', 'bei'], 'safe'],
            [['g_id', 's_id'], 'integer'],
            [['t_num', 't_total'], 'number'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = Sctotal::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        $query->andFilterWhere([
            'g_id' => $this->g_id,
            's_id' => $this->s_id,
            't_num' => $this->t_num,
            't_total' => $this->t_total,
        ]);

        $query->andFilterWhere(['like', 't_id', $this->t_id])
            ->andFilterWhere(['like', 't_name', $this->t_name])
            ->andFilterWhere(['like', 'bei2', $this->bei2])
            ->andFilterWhere(['like', 'bei', $this->bei]);

        return $dataProvider;
    }
}
